package com.xjtu.platform.user.consultor.consultRecord.dao;

import com.xjtu.platform.user.consultor.consultRecord.ConsultRecordDto;
import com.xjtu.platform.user.consultor.consultRecord.ExcelModel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @创建人 MBY381
 * @创建时间 2022/7/3 09:31
 * @描述 暂无
 */


@Mapper
public interface ConsultRecordDao {
    @Select("SELECT a.start_time as start_time,a.end_time as end_time,a.consult_id as consult_id,a.visit_id as visit_id,a.comment as comment,a.count_num as count,a.state as state,b.student_id as student_id,concat(c.day,' ',d.start_time) as plan_start_time,concat(c.day,' ',d.end_time) as plan_end_time,c.place_name as place\n" +
            "FROM consult as a,first_visit as b,duty as c,time as d\n" +
            "WHERE a.visit_id = b.visit_id and b.visiter_id=#{consultant_id} and c.duty_id = a.duty_id and c.time_id = d.time_id and a.state!=0\n" +
            "order by count DESC")
    List<ConsultRecordDto> getList(@Param("consultant_id") String consultant_id);


    @Update("update consult set state=#{state},comment=#{comment},start_time=#{start_time},end_time=#{end_time} " +
            "where visit_id=#{visit_id} and count_num=#{count}")
    void updateInfo(ConsultRecordDto dto);


    @Update("update consult set state=0 where count_num>#{count} and visit_id=#{visit_id}")
    void endUpConsult(ConsultRecordDto dto);

    @Update("update consult set state=2 where visit_id=#{visit_id} and count_num=#{count}+1")
    void activateNext(ConsultRecordDto dto);

    @Update("update first_visit set status ='finish' where visit_id=#{visit_id}")
    void endUpVisit(ConsultRecordDto dto);

    @Select("SELECT comment FROM consult WHERE visit_id=#{visit_id} and state = 4")
    String findPath(@Param("visit_id") String visit_id);

    @Update("update consult set comment =#{path} where visit_id=#{visit_id} and state = 4 ")
    void updatePath(@Param("visit_id") String visit_id, @Param("path") String path);

    @Select("select a.visit_id,b.student_id,a.start_time,a.end_time,c.place_name as place,a.comment,a.count_num as count,a.state from consult as a,first_visit as b,duty as c where" +
            " a.visit_id=#{visit_id} and b.visit_id=#{visit_id} and c.duty_id = a.duty_id and a.state!=0")
    List<ExcelModel> getListForFile(@Param("visit_id") String visit_id);

    @Select("select student_id from first_visit where visit_id=#{visit_id}")
    String findStudentID(@Param("visit_id") String visit_id);
}
